/**
 * 
 */
package com.cgbsoft.financial.common;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * @author CX
 *
 */
public class ConfigurationManager {
	
	/** 配置名字 */
	public static final String SHARED_PREFERENCE_NAEM = "com.cgbsoft.financial";
	
	/** 是否需要密码 */
	public static final String NEED_PASSWORD="NEED_PASSWORD";
	/** 当前密码 */
	public static final String PASS_WORD = "";
	
	public static final String IF_DB_STORE = "IS_USE_DB_STORE";
	
	/** 本类实例 */
	private static ConfigurationManager instance;
	private static SharedPreferences sp;
	
	private ConfigurationManager() {}
	
	public static ConfigurationManager getInstance(Context context) {
		
		if (instance == null) {
			instance = new ConfigurationManager();
			sp = context.getSharedPreferences(SHARED_PREFERENCE_NAEM, Context.MODE_WORLD_WRITEABLE | Context.MODE_WORLD_READABLE);
		}
		
		return instance;
	}
	
	/**
	 * @param key
	 * @param defValue
	 * @return
	 */
	public String getStringConfig(String key, String defValue) {
		return sp.getString(key, defValue);
	}
	
	/**
	 * @param key
	 * @param value
	 */
	public void setStringConfig(String key, String value) {
		sp.edit().putString(key, value).commit();
	}
	
	/**
	 * 获取布尔值配置
	 * @param key
	 * @param defValue
	 * @return
	 */
	public Boolean getBooleanConfig(String key, boolean defValue) {
		return sp.getBoolean(key, defValue);
	}
	
	/**
	 * 设置布尔值配置
	 * @param key
	 * @param value
	 */
	public void setBooleanConfig(String key, boolean value) {
		sp.edit().putBoolean(key, value).commit();
	}
	
	/**
	 * 反转布尔设置
	 * @param key
	 */
	public void toggleBooleanConfig(String key) {
		setBooleanConfig(key, !getBooleanConfig(key, false));
	}
}
